package com.cizzy.user.entity.dto;

import cn.hutool.core.bean.BeanUtil;
import com.cizzy.user.entity.User;
import com.cizzy.user.entity.UserCount;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class UserInfoDTO {
    private Long userId;
    private String token;
    private String avatar;

    private String nickname;

    private String signature;

    private Long followCount = 0L;

    private Long followerCount = 0L;

    private Long favoriteCount = 0L;

    private Long workCount = 0L;

    private Long collectCount = 0L;

    public UserInfoDTO(User user, UserCount userCount) {
        this.userId = user.getUserId();
        this.avatar = user.getAvatar();
        this.nickname = user.getNickname();
        this.signature = user.getSignature();
        this.token = user.getToken();
        if (userCount != null) {
            this.favoriteCount = userCount.getFavoriteCount();
            this.followCount = userCount.getFollowCount();
            this.followerCount = userCount.getFollowerCount();
            this.workCount = userCount.getWorkCount();
        }
    }

    public void convertFromUser(User user) {
        this.userId = user.getUserId();
        this.avatar = user.getAvatar();
        this.nickname = user.getNickname();
        this.signature = user.getSignature();
    }

    public void convertFromUserCount(UserCount userCount) {
        this.followCount = userCount.getFollowCount();
        this.followerCount = userCount.getFollowerCount();
        this.favoriteCount = userCount.getFavoriteCount();
        this.workCount = userCount.getWorkCount();
    }
}
